<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        font-size: 28px;
      }
    </style>
  </head>

  <body>
    <div id="message"></div>

    <script>
      message.innerHTML += `i am ${navigator.onLine ? "online" : "offline"}<br />`;
      window.onoffline = function () {
        message.innerHTML += "i am offline <br />";
      };
      window.ononline = function () {
        message.innerHTML += "i am online <br />";
      };
    </script>
  </body>
</html>
